package ru.xpparty.scanner;

import com.google.inject.Inject;

import ru.xpparty.scanner.model.ScanRequest;

/**
 * Heart of program. Performs call of underlying classes by given request and
 * returns result of scanning.
 * 
 * @author xp.party
 * 
 */
public class ScanningManager {
	private SocketScannerFactory factory;

	/**
	 * 
	 * @param factory
	 *            factory of socket scanners
	 */
	@Inject
	public void setSocketScannerFactory(SocketScannerFactory factory) {
		this.factory = factory;
	}

	/**
	 * Performs scanning ports on host found in given request. Returns result of
	 * scanning.
	 * 
	 * @param request
	 *            request to scanner
	 * @return result of scanning
	 */
	public ScanResult scan(ScanRequest request) {
		ScanResult result = new ScanResult(request.getHost());
		for (int port = request.getStartPort(); port <= request.getEndPort(); port++) {
			SocketScanner scanner = factory.create(request.getHost(), port);
			result.append(port, scanner.scan());
		}
		
		return result;
	}
	
	
}
